package com.hl.sfzy.controller;

import com.hl.sfzy.constant.CommonConstant;
import com.hl.sfzy.constant.Result;
import com.hl.sfzy.entity.SysCourses;
import com.hl.sfzy.entity.SysQuestion;
import com.hl.sfzy.pojo.Course;
import com.hl.sfzy.service.SysCoursesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author ffc
 * @version 1.0
 * @description: TODO
 * @className: SysCoursesController
 * @date 2024/7/13 13:23
 */

@RestController
public class SysCoursesController {
    @Autowired
    private SysCoursesService sysCoursesService;

    //新增课程
    @PostMapping("/sysCourses")
    public Result add(@RequestBody SysCourses sysCourses){
        System.out.println("-------------------------------------------------");
        System.out.println(sysCourses);
        return sysCoursesService.add(sysCourses) > 0 ? Result.success() : Result.error();
    }

    //根据id删除课程
    @DeleteMapping("/sysCourses/{id}")
    public Result remove(@PathVariable Integer id){
        return sysCoursesService.remove(id) > 0 ? Result.success() : Result.error();
    }

    //根据id批量删除课程
    @DeleteMapping("/sysCourses")
    public Result removeBatch(Integer[] ids){
        return sysCoursesService.removeBatch(ids) > 0 ? Result.success() : Result.error();
    }

    //修改课程
    @PutMapping("/sysCourses")
    public Result edit(@RequestBody SysCourses sysCourses){
        return sysCoursesService.edit(sysCourses) > 0 ? Result.success() : Result.error();
    }

    //根据条件课程
    @GetMapping("/sysCourses")
    public Result find(SysCourses sysCourses){
        List<SysCourses> list = sysCoursesService.find(sysCourses);
        return  Result.success(list);
    }

    //根据id查找课程
    @GetMapping("/sysCourses/{id}")
    public Result findById(@PathVariable("id") Integer id){
        SysCourses sysCourses = sysCoursesService.findById(id);
        return  Result.success(sysCourses);
    }

    //根据条件分页查找课程
    @GetMapping("/sysCourses/page")
    public Result findPage(@RequestParam(value = CommonConstant.PAGE_NUM,required = true,defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum ,
                           @RequestParam(value = CommonConstant.PAGE_SIZE,required = true,defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize ,
                           SysCourses sysCourses){
        Map<String, Object> map = sysCoursesService.findPage(pageNum, pageSize, sysCourses);
        return  Result.success(map);
    }

    //根据排序规则条件分页查找课程
    @GetMapping("/sysCourses/collation")
    public Result findByCollation(@RequestParam(value = CommonConstant.PAGE_NUM,required = true,defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum ,
                           @RequestParam(value = CommonConstant.PAGE_SIZE,required = true,defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize ,
                                  Course course){
        List<SysCourses> list = sysCoursesService.findByCollation(pageNum, pageSize, course);
        return  Result.success(list);
    }
}
